﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace IEWebSite.Pages.ActivitateDidactica
{
	public partial class ProgramaCurs : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			Response.Clear();
			Response.ClearHeaders();
			Response.ClearContent();

			if (!Request.QueryString.AllKeys.Contains("idCurs"))
			{
				Response.Redirect("~/Error.aspx");
				return;
			}
		
			using (SqlConnection sqlConn = Utils.GetSqlConnection())
			{
				sqlConn.Open();
				SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("select Fisier, FisierMimeType FROM Curs WHERE IdCurs = @IdCurs", sqlConn);
				SqlParameter sqlParam = new SqlParameter("IdCurs",SqlDbType.Int);
				sqlParam.Value = Int32.Parse(Request.QueryString["idCurs"]);
				sqlCmd.Parameters.Add(sqlParam);
				SqlDataReader sqlDataReader = sqlCmd.ExecuteReader();
				sqlDataReader.Read();
				if (sqlDataReader["Fisier"] != DBNull.Value)
				{
					Response.ContentType = sqlDataReader["FisierMimeType"].ToString();
					Response.BinaryWrite((byte[])sqlDataReader["Fisier"]);
				}
				else
					lbMessage.Text = "Fisierul cerut nu exista pe server!";
				if (sqlDataReader != null) sqlDataReader.Close();
			}
		}
	}
}
